<html>
<head>
	<script>
		function createNotification(title, text) {
			var notif = webkitNotifications.createNotification('favicon.png', title, text);
			var delay = localStorage['autoclose'];

			/* Use auto-close default value */
			if (delay == undefined)
				delay = 5;

			/* Auto-close function */
			if (delay > 0) {
				notif.ondisplay = function(event) {
					setTimeout(function() {
						event.currentTarget.cancel();
					}, delay * 900);
				}
			}

			/* Display notification */
			notif.show();
		}

		chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
			/* Check request */
			switch (request.method) {
			case 'showNotification':
				createNotification(request.title, request.text);
				break;

			case 'getLocalStorage':
				sendResponse({ data: localStorage[request.key] });
				break;
			}
		});
	</script>
</head>
</html>
